from typing import List

"""
思路：
和score一样，但是有点区别，我们可以不用真的翻转数组，只要统计就行了
需要把已经翻转的行考虑进去

值  已翻转  是否统计成0
0   0         1
0   1         0
1   0         0  
1   1         1
"""


class Solution:
    def matrixScore(self, A: List[List[int]]) -> int:
        m = len(A)
        n = len(A[0])

        res = 0
        for j in range(n):
            if j == 0:
                res = (2 ** (n - 1)) * m
                continue
            zero_count = 0
            for i in range(m):
                if A[i][0] == A[i][j]:
                    zero_count += 1
            if zero_count > m / 2:
                res += (2 ** (n - 1 - j)) * zero_count
            else:
                res += (2 ** (n - 1 - j)) * (m - zero_count)
        return res

